package com.gambi.tapestry.utils;

import javax.servlet.http.HttpServletRequest;

import org.apache.tapestry5.services.Request;

import com.google.gwt.user.server.rpc.RPCRequest;

public class GWTUtils {

	public static boolean isGwtEncryptedRequest(HttpServletRequest request) {
		String contentType = request.getHeader("Content-Type");
		if (contentType == null) {
			return false;
		}
		return contentType.contains("text/x-gwt-rpc");
	}
	
	public static boolean isGwtPlainRequest(HttpServletRequest request) {
		String contentType = request.getHeader("Content-Type");
		if (contentType == null) {
			return false;
		}
		return contentType.contains("text/gwt");
	}

	public static boolean isGwtEncryptedRequest(Request request) {
		return request.getAttribute(RPCRequest.class.getName()) != null;
	}

	
	public static boolean isGwtEventBubblingBlockinRequest(
			HttpServletRequest httpServletRequest) {
		Boolean blocking = (Boolean) httpServletRequest.getAttribute("BLOCKING");
		if( blocking == null ){
			return false;
		}
		return blocking;
	}
}
